package com.villaday.idf.custom.pop;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.m7.imkfsdk.KfStartHelper;
import com.moor.imkf.model.entity.CardInfo;
import com.villaday.idf.R;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.model.LoginEntity;
import com.villaday.idf.model.Presell_detail;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model3.MessageEntity;
import com.villaday.idf.model3.Messages;
import com.villaday.idf.model3.customerServiceStaffEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.ToastUtil;

import java.util.HashMap;
import java.util.Map;

import razerdp.basepopup.BasePopupWindow;

import static android.content.Context.CLIPBOARD_SERVICE;

public class HuiYuanMorePop extends BasePopupWindow {
    private Handler mHandler;
    private Context context;
    private Activity activity;

    Gson gson = new GsonBuilder().create();
    private final TextView tv_link;
    private final TextView tv_copy;


    public HuiYuanMorePop(final Context context, final Activity activity) {
        super(context);
        this.context = context;
        this.activity = activity;
        findViewById(R.id.tv_cancle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mHandler = new Handler();


      //  buildAnima();
        setBackground(0);
        setBackgroundColor(Color.parseColor("#B3000000"));
        setOutSideDismiss(true);
        setKeepSize(true);
        setBlurBackgroundEnable(true);
        tv_link = findViewById(R.id.tv_link);

        tv_copy = findViewById(R.id.tv_copy);
        RefreshtokenEntity.BodyBean userInfo = SharedPreferencesUtil.getRoleInfo(context);
        if (userInfo != null && userInfo.getMerchant() != null && userInfo.getMerchant().getPcUrl() != null) {
            final String pcUrl = userInfo.getMerchant().getPcUrl();
            tv_link.setText("链接地址：" + pcUrl);
            tv_copy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ToastUtil.initToast(context, "已复制链接");
                    ClipboardManager mClipboardManager = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
                    ClipData mClipData = ClipData.newPlainText("test", pcUrl);
                    mClipboardManager.setPrimaryClip(mClipData);
                    dismiss();
                }
            });
        }


    }


    // 必须实现，这里返回您的contentView
    // 为了让库更加准确的做出适配，强烈建议使用createPopupById()进行inflate
    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.huiyuan_more);
    }


    private AnimationSet mAnimationSet;

    private void buildAnima() {
        ScaleAnimation mScaleAnimation = new ScaleAnimation(1f, 2f, 1f, 2f, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        mScaleAnimation.setDuration(200);
        mScaleAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        mScaleAnimation.setFillAfter(false);

        AlphaAnimation mAlphaAnimation = new AlphaAnimation(1, .2f);
        mAlphaAnimation.setDuration(400);
        mAlphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
        mAlphaAnimation.setFillAfter(false);

        mAnimationSet = new AnimationSet(false);
        mAnimationSet.setDuration(400);
        mAnimationSet.addAnimation(mScaleAnimation);
        mAnimationSet.addAnimation(mAlphaAnimation);
        mAnimationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        dismiss();
                    }
                }, 150);

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

/*
    @Override
    protected Animation onCreateShowAnimation() {
        Animation showAnima = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
                1f,
                Animation.RELATIVE_TO_PARENT,
                0,
                Animation.RELATIVE_TO_PARENT,
                0,
                Animation.RELATIVE_TO_PARENT,
                0);
        showAnima.setInterpolator(new DecelerateInterpolator());
        showAnima.setDuration(350);
        return showAnima;
    }

    @Override
    protected Animation onCreateDismissAnimation() {
        Animation exitAnima = new TranslateAnimation(Animation.RELATIVE_TO_PARENT,
                0f,
                Animation.RELATIVE_TO_PARENT,
                1f,
                Animation.RELATIVE_TO_PARENT,
                0,
                Animation.RELATIVE_TO_PARENT,
                0);
        exitAnima.setInterpolator(new DecelerateInterpolator());
        exitAnima.setDuration(350);
        return exitAnima;
    }*/


}


